/*
 * @lc app=leetcode.cn id=763 lang=typescript
 *
 * [763] 划分字母区间
 */

// @lc code=start
function partitionLabels(s: string): number[] {
    let arr = new Array(26);
    const codePointA = 'a'.charCodeAt(0);
    for (let i = 0; i < s.length; i++) {
        arr[s.charCodeAt(i) - codePointA] = i;
    }

    const res: any = [];
    let start = 0, end = 0;
    for (let i = 0; i < s.length; i++) {
        end = Math.max(end, arr[s.charCodeAt(i) - codePointA]);
        if (end === i) {
            res.push(end - start + 1);
            start = end + 1;
        }

    }
    // console.log(res);
    return res;
};

// partitionLabels('ababcbacadefegdehijhklij');
// @lc code=end

